<%@page import="cn.com.gzqd.model.Book"%>
<%@page import="cn.com.gzqd.serviceimpl.BookServiceImpl"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.Timestamp"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<%
request.setCharacterEncoding("UTF-8");
%>
<body>
<%		BookServiceImpl psi=new BookServiceImpl();
		Timestamp ts = new Timestamp(System.currentTimeMillis());   
		Book book=new Book();
		
		if(!("".equals(request.getParameter("Bookname")))){
			System.out.println(request.getParameter("Bookname"));
			book.setBookname(request.getParameter("Bookname"));
		}
		else{%>
		<jsp:forward page="erro.jsp"></jsp:forward>
	<%
	}
		if(!("".equals(request.getParameter("Author")))){
			book.setAuthor(request.getParameter("Author"));
		}
		else{%>
		<jsp:forward page="erro.jsp"></jsp:forward>
	<%
	}
		if(!("".equals(request.getParameter("Publishing")))){
			book.setPublishing(request.getParameter("Publishing"));
		}else{%>
		<jsp:forward page="erro.jsp"></jsp:forward>
	<%
	}
		if(!("".equals(request.getParameter("Quantity")))){
			book.setQuantity(request.getParameter("Quantity"));
			}else{%>
		<jsp:forward page="erro.jsp"></jsp:forward>
	<%
	}
		if(!("1".equals(request.getParameter("Purchased")))){
			if(!("".equals(request.getParameter("Buytime")))){			 	
				System.out.println("购买时间");			
				System.out.println(request.getParameter("Buytime"));	
				SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");    
            	java.util.Date date = format1.parse(request.getParameter("Buytime"));    
            	SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");    
            	String sdate=format2.format(date);        
            	book.setBuytime(Timestamp.valueOf(sdate));   	      				
	}
	else{%>
	<jsp:forward page="erro.jsp"></jsp:forward>
<%
}
		}else{
			book.setBuytime(Timestamp.valueOf("1000-01-01 00:00:00"));
			System.out.println("购买时间为null");	
		}
			
		System.out.println("是否购买");
		System.out.println(request.getParameter("Purchased"));	
		if(!("".equals(request.getParameter("Purchased")))){
				if(!("1".equals(request.getParameter("Purchased")))){
					book.setPurchased("是");
			}else
				book.setPurchased("否");
			}else{%>
			<jsp:forward page="erro.jsp"></jsp:forward>
		<%
		}
		if(!("".equals(request.getParameter("Ps")))){			
			book.setPs(request.getParameter("Ps"));
		}else{
			book.setPs(null);
	}
		try{
			if(psi.Create(book)){
		
	%>
	<h3>信息添加成功！</h3>
	<jsp:forward page="PageServlet"></jsp:forward>
	<%
			}else{
	%>
	<h3>信息添加失败</h3>
	<%
		}
			}
			catch(Exception e){
				e.printStackTrace();
				}
			
	%>
</body>
</html>